#ifndef __TREE_H__
#define __TREE_H__

#include "wx/treectrl.h"

#define USE_GENERIC_TREECTRL 1

#if USE_GENERIC_TREECTRL
#include "wx/generic/treectlg.h"
#ifndef wxTreeCtrl
#define wxTreeCtrl wxGenericTreeCtrl
#define sm_classwxTreeCtrl sm_classwxGenericTreeCtrl
#endif
#endif

class oxTreeItemData : public wxTreeItemData
{
public:
	oxTreeItemData() {m_desc = wxT("");}
	oxTreeItemData(const wxString& desc) : m_desc(desc) { }

	const wxChar *GetDesc() const { return m_desc.c_str(); }

private:
	wxString m_desc;
};


class oxTreeCtrl : public wxTreeCtrl
{
public:

	oxTreeCtrl() {}
	oxTreeCtrl(wxWindow *parent, const wxWindowID id = wxID_ANY,
		const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize,
		long style=wxTR_DEFAULT_STYLE | wxSUNKEN_BORDER | wxTR_NO_LINES | wxTR_EDIT_LABELS | wxTR_HIDE_ROOT /*| wxTR_MULTIPLE*/);
	virtual ~oxTreeCtrl(){};

	void OnBeginDrag(wxTreeEvent& event);
	void OnEndDrag(wxTreeEvent& event);
	void OnBeginLabelEdit(wxTreeEvent& event);
	void OnEndLabelEdit(wxTreeEvent& event);
	void OnDeleteItem(wxTreeEvent& event);
	void OnContextMenu(wxContextMenuEvent& event);
	void OnItemMenu(wxTreeEvent& event);
// 	void OnGetInfo(wxTreeEvent& event);
// 	void OnSetInfo(wxTreeEvent& event);
// 	void OnItemExpanded(wxTreeEvent& event);
// 	void OnItemExpanding(wxTreeEvent& event);
// 	void OnItemCollapsed(wxTreeEvent& event);
// 	void OnItemCollapsing(wxTreeEvent& event);
	void OnSelChanged(wxTreeEvent& event);
	void OnSelChanging(wxTreeEvent& event);
	void OnTreeKeyDown(wxTreeEvent& event);
// 	void OnItemActivated(wxTreeEvent& event);
// 	void OnItemStateClick(wxTreeEvent& event);
	void OnItemRClick(wxTreeEvent& event);

	void OnRMouseDown(wxMouseEvent& event);



	void DoSortChildren(const wxTreeItemId& item, bool reverse = false)
	{ m_reverseSort = reverse; wxTreeCtrl::SortChildren(item); }
	void DoEnsureVisible() { if (m_lastItem.IsOk()) EnsureVisible(m_lastItem); }

	void ShowMenu(wxTreeItemId id, const wxPoint& pt);

	void SetLastItem(wxTreeItemId id) { m_lastItem = id; }

protected:
	virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);

private:

	bool         m_reverseSort;             // flag for OnCompareItems
	wxTreeItemId m_lastItem,                // for OnEnsureVisible()
		m_draggedItem;             // item being dragged right now

	// NB: due to an ugly wxMSW hack you _must_ use DECLARE_DYNAMIC_CLASS()
	//     if you want your overloaded OnCompareItems() to be called.
	//     OTOH, if you don't want it you may omit the next line - this will
	//     make default (alphabetical) sorting much faster under wxMSW.
	DECLARE_DYNAMIC_CLASS(oxTreeCtrl)
	DECLARE_EVENT_TABLE()
};


#endif